﻿namespace Snipps
{
    using System;
    using System.Linq;
    using System.Reflection;

    using Snipps.Infrastructure;

    public class Program
    {
        [STAThread]
        public static void Main()
        {
            const string resourcesRef = "Snipps.Libs.";
            var assem = Assembly.GetExecutingAssembly();
            var resourcesNames = assem.GetManifestResourceNames().Where(x => x.EndsWith(".dll"));
            foreach (var resourceName in resourcesNames)
            {
                EmbeddedAssembly.Load(resourceName, resourceName.Replace(resourcesRef, string.Empty));
            }

            AppDomain.CurrentDomain.AssemblyResolve += OnResolveAssembly;
            App.Main();
        }

        private static Assembly OnResolveAssembly(object sender, ResolveEventArgs args)
        {
            return EmbeddedAssembly.Get(args.Name);
        }
    }
}